package com.lsht.web.core.config;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class mathZuoBiaoXi {

	public static void main(String[] args) {
		double lon1 = (Math.PI / 180) * 116.228902;//开始经度
		double lon2 = (Math.PI / 180) * 116.234017;//结束经度
		double lat1 = (Math.PI / 180) * 39.954825;//开始纬度
		double lat2 = (Math.PI / 180) * 39.954913;//结束纬度

		// 地球半径
		double R = 6371;

		// 两点间距离 km，如果想要米的话，结果*1000就可以了
		double value = Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)) * R;

		double roundedValue = round(value * 1000, 2);
		System.out.println(roundedValue);
	}

	public static double round(double value, int places) {
		if (places < 0) throw new IllegalArgumentException();

		BigDecimal bd = BigDecimal.valueOf(value);
		bd = bd.setScale(places, RoundingMode.HALF_UP);
		return bd.doubleValue();
	}
}
